﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AtletIS.Shared.Helpers
{
    public static class DgvLayoutHelper
    {
        /// <summary>
        ///  Layout pre vyhľadanie v prihláškach
        /// </summary>
        public static void FindSignupLayout(DataGridView dgv)
        {
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {
                dgvc.Visible = false;
            }

            dgv.Columns["StartNumber"].Visible = true;
            dgv.Columns["StartNumber"].DisplayIndex = 0;
            dgv.Columns["StartNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["StartNumber"].HeaderText = "Št. číslo";

            dgv.Columns["Surname"].Visible = true;
            dgv.Columns["Surname"].DisplayIndex = 1;
            dgv.Columns["Surname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Surname"].HeaderText = "Priezvisko";

            dgv.Columns["FirstName"].Visible = true;
            dgv.Columns["FirstName"].DisplayIndex = 2;
            dgv.Columns["FirstName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["FirstName"].HeaderText = "Meno";

            dgv.Columns["Name"].Visible = true;
            dgv.Columns["Name"].DisplayIndex = 3;
            dgv.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Name"].HeaderText = "Disciplína";
        }

        /// <summary>
        ///  Layout pre behy
        /// </summary>
        public static void RunningLayout(DataGridView dgv)
        {
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {
                dgvc.Visible = false;
            }

            dgv.Columns["Rank"].Visible = true;
            dgv.Columns["Rank"].DisplayIndex = 0;
            dgv.Columns["Rank"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Rank"].HeaderText = "Poradie";

            dgv.Columns["StartNumber"].Visible = true;
            dgv.Columns["StartNumber"].DisplayIndex = 1;
            dgv.Columns["StartNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["StartNumber"].HeaderText = "Št. číslo";

            dgv.Columns["Surname"].Visible = true;
            dgv.Columns["Surname"].DisplayIndex = 2;
            dgv.Columns["Surname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Surname"].HeaderText = "Priezvisko";

            dgv.Columns["FirstName"].Visible = true;
            dgv.Columns["FirstName"].DisplayIndex = 3;
            dgv.Columns["FirstName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["FirstName"].HeaderText = "Meno";

            dgv.Columns["Birthdate"].Visible = true;
            dgv.Columns["Birthdate"].DisplayIndex = 4;
            dgv.Columns["Birthdate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Birthdate"].HeaderText = "Dát. nar.";

            dgv.Columns["Club"].Visible = true;
            dgv.Columns["Club"].DisplayIndex = 5;
            dgv.Columns["Club"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Club"].HeaderText = "Klub";
            
            dgv.Columns["Result"].Visible = true;
            dgv.Columns["Result"].DisplayIndex = 6;
            dgv.Columns["Result"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Result"].HeaderText = "Čas";
        }

        /// <summary>
        ///  Layout pre 6-pokusové disciplíny
        /// </summary>
        public static void SixAttempsLayout(DataGridView dgv)
        {
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {
                dgvc.Visible = false;
            }

            dgv.Columns["StartNumber"].Visible = true;
            dgv.Columns["StartNumber"].ReadOnly = true;
            dgv.Columns["StartNumber"].DisplayIndex = 0;
            dgv.Columns["StartNumber"].HeaderText = "Št. číslo";
            dgv.Columns["StartNumber"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgv.Columns["StartNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["StartNumber"].SortMode = DataGridViewColumnSortMode.NotSortable;

            dgv.Columns["Surname"].Visible = true;
            dgv.Columns["Surname"].ReadOnly = true;
            dgv.Columns["Surname"].DisplayIndex = 1;
            dgv.Columns["Surname"].HeaderText = "Priezvisko";
            dgv.Columns["Surname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Surname"].SortMode = DataGridViewColumnSortMode.NotSortable;

            dgv.Columns["FirstName"].Visible = true;
            dgv.Columns["FirstName"].ReadOnly = true;
            dgv.Columns["FirstName"].DisplayIndex = 2;
            dgv.Columns["FirstName"].HeaderText = "Meno";
            dgv.Columns["FirstName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["FirstName"].SortMode = DataGridViewColumnSortMode.NotSortable;

            dgv.Columns["1"].Visible = true;
            dgv.Columns["1"].Width = 60;
            dgv.Columns["1"].SortMode = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns["2"].Visible = true;
            dgv.Columns["2"].Width = 60;
            dgv.Columns["2"].SortMode = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns["3"].Visible = true;
            dgv.Columns["3"].Width = 60;
            dgv.Columns["3"].SortMode = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns["4"].Visible = true;
            dgv.Columns["4"].Width = 60;
            dgv.Columns["4"].SortMode = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns["5"].Visible = true;
            dgv.Columns["5"].Width = 60;
            dgv.Columns["5"].SortMode = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns["6"].Visible = true;
            dgv.Columns["6"].Width = 60;
            dgv.Columns["6"].SortMode = DataGridViewColumnSortMode.NotSortable;
        }

        /// <summary>
        ///  Layout pre X-pokusové disciplíny
        /// </summary>
        public static void MultiAttemptsLayout(DataGridView dgv, string note)
        {
            string[] arrNote = note.Split(',');
            
            foreach (DataGridViewColumn dgvc in dgv.Columns)
            {
                dgvc.Visible = false;
            }

            dgv.Columns["StartNumber"].Visible = true;
            dgv.Columns["StartNumber"].ReadOnly = true;
            dgv.Columns["StartNumber"].Frozen = true;
            dgv.Columns["StartNumber"].DisplayIndex = 0;
            dgv.Columns["StartNumber"].HeaderText = "Št. číslo";
            dgv.Columns["StartNumber"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgv.Columns["StartNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["StartNumber"].SortMode = DataGridViewColumnSortMode.NotSortable;

            dgv.Columns["Surname"].Visible = true;
            dgv.Columns["Surname"].ReadOnly = true;
            dgv.Columns["Surname"].Frozen = true;
            dgv.Columns["Surname"].DisplayIndex = 1;
            dgv.Columns["Surname"].HeaderText = "Priezvisko";
            dgv.Columns["Surname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["Surname"].SortMode = DataGridViewColumnSortMode.NotSortable;

            dgv.Columns["FirstName"].Visible = true;
            dgv.Columns["FirstName"].ReadOnly = true;
            dgv.Columns["FirstName"].Frozen = true;
            dgv.Columns["FirstName"].DisplayIndex = 2;
            dgv.Columns["FirstName"].HeaderText = "Meno";
            dgv.Columns["FirstName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgv.Columns["FirstName"].SortMode = DataGridViewColumnSortMode.NotSortable;

            int displayIndex = 3;
            foreach (string str in arrNote)
            {
                if (!string.IsNullOrEmpty(str))
                {
                    dgv.Columns[str].Visible = true;
                    dgv.Columns[str].DisplayIndex = displayIndex;
                    dgv.Columns[str].HeaderText = str;
                    dgv.Columns[str].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    dgv.Columns[str].SortMode = DataGridViewColumnSortMode.NotSortable;
                    displayIndex += 1;
                }
            }
        }




    }
}
